package com.lsk.mps.backend.mapper;

import com.lsk.mps.backend.model.User;
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.InternetHeaders;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user limit ${offset}, ${rows}")
    List<User> queryAllUsers(@Param("offset") Integer offset, @Param("rows") Integer rows);
    @Select("select * from user")
    List<User> queryAllUsersNoPaged();
    @Select("select * from user where username=#{username}")
    User queryUserByName(@Param("username") String username);
    @Select("select count(id) from user")
    Integer userCount();
    @Select("select username from user")
    List<String> queryUsernames();
    @Insert("insert into user(username, password, role) value(#{username}, #{password}, #{role})")
    void addUser(User user);
    @Update("update user set username=#{username} where id=#{id}")
    void updateUsername(@Param("username") String newUsername, @Param("id") Integer id);
    @Update("update user set password=#{password} where id=#{id}")
    void updatePassword(@Param("password") String newPassword, @Param("id") Integer id);
    @Update("update user set role=#{role} where id=#{id}")
    void updateRole(@Param("role") String role, @Param("id") Integer id);
    @Delete("delete from user where id=#{id}")
    void deleteUser(@Param("id") Integer id);

}
